import Axios from "axios";

const Request = Axios.create({
    baseURL: "/",
    timeout: 20000,
});

// Request.interceptors.request.use((req) => {
//     return req;
// });

Request.interceptors.response.use((response) => {
    // 直接返回响应，让调用方处理数据
    return response;
}, (error) => {
    // 统一处理错误
    return Promise.reject(error);
});

// 获取API基础路径
export function getApiBasePath () {
  if (process.env.NODE_ENV === 'development') {
    // 开发环境
    const devPath = process.env.VUE_APP_DOMAIN || 'http://localhost:3000'
    return devPath;
  } else {
    // 生产环境
    const prodPath = window.location.origin + '/php';
    return prodPath;
  }
}

export default Request;